package com.sm.healthy.utils;

import java.util.List;

/**
 * Created by shenmai8 on 2018/4/21.
 */

public class DataUtils {
    public static String data2hex(byte data[],int len){
        char dat[]=new char[len*3];
        char val;

        for(int i=0;i<len;i++){
            val = (char)((data[i]&0xF0)>>4);
            if(val > 9) {
                val -= 10;
                val += 'A';
            }else{
                val += '0';
            }
            dat[3*i]=val;
            val = (char)((data[i]&0xF));
            if(val > 9) {
                val -= 10;
                val += 'A';
            }else{
                val += '0';
            }
            dat[3*i+1]=val;
            dat[3*i+2]=' ';
        }
        return new String(dat);
    }
    public static byte[] subByteArr(byte[] data, int begin, int count){
        byte[] b = new byte[count];
        System.arraycopy(data,begin,b,0,count);
        return b;
    }

    public static int getAve(List<Integer> data) {
        int ave = 0,sum = 0;
        for (int i = 0 ; i < data.size() ; i++){
            sum+=data.get(i);
        }
        ave = sum/data.size();
        return ave;
    }
    public static double getDoubleAve(List<Double> data) {
        double ave = 0,sum = 0;
        for (int i = 0 ; i < data.size() ; i++){
            sum+=data.get(i);
        }
        ave = sum/(double) (data.size());
        return ave;
    }
}
